<?php

namespace Biz\model\brandActivity;

use Doraemon\pockets\datebase\BaseDbModel;

class BlindBoxPointTask extends BaseDbModel
{
    const _CONFIG_FILE_ = 'db_store';

    const _CONFIG_SELECT_ = 'db_brand_activity';

    const _DATABASE_ = 'brand_activity';

    const _TABLE_NAME = 'blind_box_point_task';

    const TASK_TYPE_SIGN_IN = 1;//每日签到
    const TASK_TYPE_FAVORITE_GOODS = 2;//收藏一个商品
    const TASK_TYPE_SHARE_GOODS = 3;//分享一个商品（不在我的任务列表）
    const TASK_TYPE_LIKE = 4;//点赞
    const TASK_TYPE_RELATE_WIKI = 5;//发布一条绑定商品的内容
    const TASK_TYPE_RELATE_TOPIC = 6;//参与话题
    const TASK_TYPE_FOLLOW_BRAND = 11;//关注品牌（不在我的任务列表）

    const TASK_TYPE_ARRAY = [
        self::TASK_TYPE_SIGN_IN,
        self::TASK_TYPE_FAVORITE_GOODS,
        self::TASK_TYPE_LIKE,
        self::TASK_TYPE_RELATE_WIKI,
        self::TASK_TYPE_RELATE_TOPIC
    ];

    const TASK_STATE_UN_START = 0;//未开始
    const TASK_STATE_WAIT_FINISH = 1;//待完成，待领取积分
    const TASK_STATE_FINISHED = 2;//已完成

    public static function getByWhere($where, $select = '*')
    {
        return self::get($select, $where);
    }

    public static function selectByWhere($where, $select = '*')
    {
        $list = self::select($select, $where);
        return $list;
    }

    public static function selectCountWhere($where)
    {
        $count = self::count('id', $where);
        return $count;
    }


    public static function insertData($data)
    {
        if (!isset($data['addtime'])) {
            $data['addtime'] = date('Y-m-d H:i:s');
        }
        if (!isset($data['edittime'])) {
            $data['edittime'] = date('Y-m-d H:i:s');
        }
        $ret = self::insert($data);
        if ($ret->errorCode() !== '00000') {
            return false;
        }
        return self::id();
    }


    public static function updateData($data, $where)
    {
        if (!isset($data['edittime'])) {
            $data['edittime'] = date('Y-m-d H:i:s');
        }
        $ret = self::update($data, $where);
        if ($ret->errorCode() !== '00000') {
            return false;
        }
        return true;
    }

}